// pages/users/volunteer/index.js
const {
  specialtyList,
} = require('../../../api/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    pageNo: 1,
    pageSize: 20,
    props: {
      name: 'name',
      code: 'code'
    },
    itemStyle: {
      width: '690rpx',
      padding: '32rpx 24rpx',
      radius: '20rpx'
    },
    loading:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},
  async getList() {
    const {
      pageNo,
      pageSize,
    } = this.data
    const params = {
      pageNo,
      pageSize
    }
    const {
      result
    } = await specialtyList(params)
    if (result.records.length < 1) return
    result.records=result.records.map(e=>{
      return  e=Object.assign(e.specialtyDetail,{specialtyCode:e.specialtyCode,isCollection:e.isCollection})
    })
    this.setData({
      total: result.total,
      ['list[' + (pageNo - 1) + ']']: result.records,
      pageNo: pageNo + 1,
    })
  },
  // 专业收藏
  collect(e) {
    this.setData({
      list: e.detail.list
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      pageNo: 1
    })
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const {
      list,
      pageSize
    } = this.data
    const count = list.length - 1
    if (list[count].length < pageSize) return
    this.getList()
  },

  goto(e) {
    const code = e.currentTarget.dataset.code
    wx.navigateTo({
      url: '/pages/major/detail/index?code=' + code,
    })
  },
})